package com.ssy.lingxi.workflow.api.model.contant;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 工作流流程名称枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-21
 */
public enum ProcessEnum {
    /**
     * 平台后台-平台会员审核 - 1
     */
    PLATFORM_MEMBER_VERIFY(1, 0, "platform_member_verify", "平台会员审核", "pmv", "memberId", 1),

    /**
     * 会员能力 - 下级会员审核 - 2
     */
    MERCHANT_MEMBER_VERIFY(2, 0, "merchant_member_verify", "会员能力会员审核", "mmv", "validateId", 1),

    /**
     * 交易能力需求发布 - 3
     */
    TRADE_REQUIREMENT_RELEASE(3, 0, "trade_requirement", "交易能力需求发布", "trr", "orderId", 1),

    /**
     * 交易能力 - 需求单外部审核 - 4
     */
    TRADE_OUTER_VALIDATE(4, 1, "trade_outer_validate", "交易能力需求单外部审核", "tov", "orderId", 1),

    /**
     * 交易能力 - 报价单内部流转 - 5
     */
    TRADE_OFFER_INNER_VALIDATE(5, 0, "trade_offer_inner_validate", "交易能力报价单内部流转", "toiv", "orderId", 1),

    /**
     * 确认需求报价单 - 内部审核流程 - 6
     */
    TRADE_CONFIRM_INNER_VALIDATE(6, 0, "trade_confirm_inner_validate", "确认需求报价单内部审核流程", "tciv", "orderId", 1),

    /**
     * 交易能力 - 商品询价 - 询价单内部工作流 - 7
     */
    TRADE_INQUIRY_INNER(7, 0, "trade_inquiry_inner", "商品询价询价单内部工作流", "tii", "orderId", 1),

    /**
     * 交易能力 - 商品询价 - 询价单外部工作流 - 8
     */
    TRADE_INQUIRY_EXTERNAL(8, 1, "trade_inquiry_external_ext", "商品询价询价单外部工作流", "teie", "orderId", 1),

    /**
     * 交易能力 - 商品询价 - 确认报价单内部流转 - 9
     */
    TRADE_CONFIRM_QUOTE_INNER(9, 0, "trade_confirm_quote_inner", "商品询价确认询价报价单内部流转", "pcpio", "orderId", 1),

    /**
     * 物流服务 - 物流单外部流转 - 11
     */
    LOGISTICS_OUTER_ORDER(11, 1, "logistics_outer_order", "物流服务物流单外部流转", "loo", "orderId", 1),

    /**
     * 交易能力 - 商品询价 - 报价单内部流程
     */
    TRADE_QUOTE_INNER(12, 0, "trade_quote_inner", "商品询价报价单内部工作流", "toip", "orderId", 1),

    /**
     * 支付能力 - 授信申请审核流程 - 13
     */
    PAY_CREDIT_APPLY_VERIFY(13, 0, "granting_credit_apply_verify", "授信申请审核流程", "gcav", "orderId", 1),


    /**
     * 采购订单 - 采购订单内部流程 - 14
     */
    PURCHASE_ORDER_INNER_VERIFY(14, 0, "purchase_order_inner_verify", "采购订单内部流程", "poiv", "orderId", 1),

    /**
     * 售后能力 - 维修申请内部流转 - 16
     */
    AFTER_SALE_REPAIR_INNER_VERIFY(16, 0, "after_sale_repair_inner_verify", "售后能力维修申请内部审核流转", "asriv", "orderId", 1),

    /**
     * 售后能力 - 退货内部审核流转 - 17
     */
    AFTER_SALE_RETURN_GOODS_INNER_VERIFY(17, 0, "after_sale_return_goods_inner_verify", "售后能力退货内部审核流转", "asrgiv", "orderId", 1),

    /**
     * 售后能力 - 售后退货外部审核(含收发货单)- 18
     */
    AFTER_SALE_RETURN_GOODS_OUTER_VERIFY(18, 1, "after_sale_return_goods_outer_verify_ext", "售后能力退货外部审核流转", "asrgov", "orderId", 1),

    /**
     * 售后能力 - 换货内部审核流转 - 19
     */
    AFTER_SALE_REPLACE_GOODS_INNER_VERIFY(19, 0, "after_sale_replace_goods_inner_verify", "售后能力换货内部审核流转", "asregiv", "orderId", 1),

    /**
     * 售后能力 - 换货外部流转 - 20
     */
    AFTER_SALE_REPLACE_GOODS_OUTER_VERIFY(20, 1, "after_sale_replace_goods_outer_verify_ext", "售后能力换货外部审核流转", "asrrgov", "orderId", 1),

    /**
     * 采购订单 - 手工确认收货发货外部流转 21
     */
    PURCHASE_ORDER_MCRSG_OUTER_VERIFY(21, 1, "purchase_order_mcrsg_outer_verify", "采购订单手工确认收货发货外部流转", "pomcrsgov", "orderId", 1),

    /**
     * 采购订单 - 订单外部流程复杂模式 22
     */
    PURCHASE_ORDER_ONE_OUTER_VERIFY(22, 1, "purchase_order_outer_verify_one_ext", "订单外部流程复杂模式", "poovone", "orderId", 1),

    /**
     * 采购订单 - 销售订单内部审核流程 23
     */
    PURCHASE_ORDER_SALE_INNER_VERIFY(23, 0, "purchase_order_sale_inner_verify", "销售订单内部审核流程", "posiv", "orderId", 1),

    /**
     * 采购订单 - 订单外部流程简单模式 24
     */
    PURCHASE_ORDER_PURCHASE_ADD_ORDER(24, 1, "purchase_order_purchase_add_order_ext", "订单外部流程简单模式", "popao", "orderId", 1),

    /**
     * 采购订单 - 订单外部流程多次支付模式 25
     */
    PURCHASE_ORDER_OUTER_VERIFY_REPEAT_PAY_DELIVERY(25, 1, "purchase_order_outer_verify_repeat_pay_delivery_ext", "订单外部流程多次支付模式", "poovrpd", "orderId", 1),

    /**
     * 加工生产外部流转 26
     */
    PNO_OUTER_VERIFY(26, 1, "pno_outer_verify_ext", "生产通知单外部流程", "pnoov", "orderId", 1),
    /**
     * 加工生产供应商内部流转 27
     */
    PNO_SUPPLIER_INNER_VERIFY(27, 0, "pno_supplier_inner_verify", "生产通知单供应商内部流程", "pnosiv", "orderId", 1),
    /**
     * 加工生产加工企业内部流转 28
     */
    PNO_PROCESS_INNER_VERIFY(28, 0, "pno_process_inner_verify", "生产通知单加工企业内部流程", "pnopiv", "orderId", 1),
    /**
     * 加工生产手工发货外部流转
     */
    PNO_MANUAL_DELIVERY_OUTER_VERIFY(29, 1, "pno_manual_delivery_outer_verify_ext", "生产通知单手工发货外部流程", "pnomdov", "orderId", 1),
    /**
     * 售后换货手工发货外部审核流转 - 30
     */
    AFTER_SALE_REPLACE_GOODS_MANUAL_DELIVERY(30, 1, "after_sale_replace_goods_manual_delivery_ext", "售后换货手工发货外部审核流转", "asrrgmdov", "orderId", 1),
    /**
     * 售后退货外部审核流转(无收发货单) - 31
     */
    AFTER_SALE_RETURN_GOODS_MANUAL_DELIVERY(31, 1, "after_sale_return_goods_manual_delivery_ext", "售后退货手工发货外部审核流转", "asrgmdov", "orderId", 1),
    /**
     * 采购询价外部流程 - 32
     */
    PURCHASE_INQUIRY_OUTER_VERIFY(32, 1, "purchase_inquiry_outer_verify_ext", "采购询价外部流程", "piov", "orderId", 1),
    /**
     * 采购询价内部流程 - 33
     */
    PURCHASE_INQUIRY_INNER_VERIFY(33, 0, "purchase_inquiry_inner_verify", "采购询价内部流程", "piiv", "orderId", 1),
    /**
     * 采购报价内部流程 - 34
     */
    PURCHASE_OFFER_INNER_VERIFY(34, 0, "purchase_offer_inner_verify", "采购报价内部流程", "pofferiv", "orderId", 1),
    /**
     * 采购确认报价内部流程 - 35
     */
    PURCHASE_CONFIRM_OFFER_INNER_VERIFY(35, 0, "purchase_confirm_offer_inner_verify", "采购确认报价内部流程", "pcofferiv", "orderId", 1),
    /**
     * 采购计划内部流程 - 36
     */
    PURCHASE_PLAN_INNER_VERIFY(36, 0, "purchase_plan_inner_verify", "采购计划内部流程", "ppiv", "orderId", 1),
    /**
     * 需求计划内部流程 - 37
     */
    NEED_PLAN_INNER_VERIFY(37, 0, "need_plan_inner_verify", "需求计划内部流程", "dpiv", "orderId", 1),
    /**
     * 合同外部流程 - 38
     */
    CONTRACT_OUTER_VERIFY(38, 1, "contract_outer_verify_ext", "合同外部流程", "cov", "orderId", 1),
    /**
     * 合同甲方内部流程 - 39
     */
    CONTRACT_PARTY_A_INNER_VERIFY(39, 1, "contract_party_a_inner_verify", "合同甲方内部流程", "cpaiv", "orderId", 1),
    /**
     * 合同乙方内部流程 - 40
     */
    CONTRACT_PARTY_B_INNER_VERIFY(40, 1, "contract_party_b_inner_verify", "合同乙方内部流程", "cpbiv", "orderId", 1),
    /**
     * 合同请款流程 - 41
     */
    CONTRACT_APPLY_AMOUNT_VERIFY(41, 1, "contract_apply_amount_verify", "合同请款流程", "caav", "orderId", 1),
    /**
     * 订单外部流程采购询价合同下单模式 - 42
     */
    ORDER_PURCHASE_INQUIRY_CONTRACT(42, 1, "purchase_order_outer_verify_two_ext", "订单外部流程采购询价合同下单模式", "poovt", "orderId", 1),
    /**
     * 售后退货外部审核流程(合同含收发货单) - 43
     */
    AFTER_SALE_RETURN_GOODS_CONTRACT_VERIFY(43, 1, "after_sale_return_goods_contract_verify_ext", "售后退货合同审核流程", "asrgcv", "orderId", 1),
    /**
     * 售后退货外部审核流程(合同无收发货单) - 44
     */
    AFTER_SALE_RETURN_GOODS_CONTRACT_MANUAL_DELIVERY(44, 1, "after_sale_return_goods_contract_manual_delivery_ext", "售后退货合同手工发货审核流程", "asrgmcdov", "orderId", 1),
    /**
     * 售后换货合同审核流转- 45
     */
    AFTER_SALE_REPLACE_GOODS_CONTRACT_VERIFY(45, 1, "after_sale_replace_goods_contract_verify_ext", "售后换货合同审核流转", "asrrgcv", "orderId", 1),
    /**
     * 售后换货合同手工发货审核流程 - 46
     */
    AFTER_SALE_REPLACE_GOODS_CONTRACT_MANUAL_DELIVERY(46, 1, "after_sale_replace_goods_contract_manual_delivery_ext", "售后换货合同手工发货审核流程", "asrrgmcdov", "orderId", 1),

    /**
     * 采购竞价单外部流转 - 47
     */
    PURCHASE_BIDDING_EXTERNAL(47, 1, "purchase_bidding_external_outer_verify_ext", "采购竞价单外部流转", "pbeov", "orderId", 1),

    /**
     * 采购竞价单内部流转 - 48
     */
    PURCHASE_BIDDING_INTERIOR(48, 1, "purchase_bidding_interior_outer_verify", "采购竞价单内部流转", "pbiov", "orderId", 1),

    /**
     * 审核竞价结果内部流转 - 49
     */
    PURCHASE_BIDDING_EXAMINE_INTERIOR(49, 1, "purchase_bidding_examine_interior_outer_verify", "采购竞价结果内部流转", "pbeiov", "orderId", 12),

    /**
     * 招投标流程 - 50
     */
    PURCHASE_INVITE_TENDER(50, 1, "purchase_invite_tender_ext", "招投标流程", "pit", "inviteTenderId", 1),

    /**
     * 会员考评流程 - 51
     */
    MEMBER_APPRAISAL_VERIFY(51, 1, "member_appraisal_verify", "会员考评流程", "mav", "appraisalId", 1),

    /**
     * 平台活动外部流程 - 52
     */
    PLATFORM_ACTIVITY_OUTER_VERIFY(52, 1, "platform_activity_outer_verify_ext", "平台活动外部流程", "mav", "appraisalId", 1),

    /**
     * 平台活动内部流程 - 53
     */
    PLATFORM_ACTIVITY_INNER_VERIFY(53, 0, "platform_activity_inner_verify", "平台活动内部流程", "mav", "appraisalId", 1),

    /**
     * 平台活动报名内部流程 - 54
     */
    PLATFORM_ACTIVITY_SIGN_UP_INNER_VERIFY(54, 0, "platform_activity_sign_up_inner_verify", "平台活动报名内部流程", "mav", "appraisalId", 1),

    /**
     * 会员活动外部流程 - 55
     */
    MEMBER_ACTIVITY_OUTER_VERIFY(55, 1, "member_activity_outer_verify_ext", "会员活动外部流程", "mav", "appraisalId", 1),

    /**
     * 会员活动内部流程 - 56
     */
    MEMBER_ACTIVITY_INNER_VERIFY(56, 1, "member_activity_inner_verify", "会员活动内部流程", "mav", "appraisalId", 1),

    /**
     * 投标流程 - 57
     */
    PURCHASE_SUBMIT_TENDER(57, 1, "purchase_submit_tender", "投标流程", "pst", "submitTenderId", 1),

    /**
     * 新增招标流程 - 58
     */
    PURCHASE_ADD_INVITE_TENDER(58, 1, "purchase_add_invite_tender", "新增招标流程", "pait", "inviteTenderId", 1),

    /**
     * 定标标流程 - 59
     */
    PURCHASE_FINISH_TENDER(59, 1, "purchase_finish_tender", "定标流程", "pft", "inviteTenderId", 1),
    /**
     * 售后退货外部审核(线下物流)流程 - 60
     */
    AFTER_SALE_RETURN_GOODS_VERIFY_OFFLINE_LOGISTICS(60, 1, "after_sale_return_goods_outer_verify_offline_logistics_ext", "售后退货外部审核线下物流流程", "asrgcv", "orderId", 1),
    /**
     * 售后退货外部审核(合同线下物流)流程 - 61
     */
    AFTER_SALE_RETURN_GOODS_VERIFY_CONTRACT_OFFLINE_LOGISTICS(61, 1, "after_sale_return_goods_outer_verify_contract_offline_logistics_ext", "售后退货外部合同审核线下物流流程", "asrgcv", "orderId", 1),
    /**
     * 售后能力 - 换货外部流转(线下物流) - 62
     */
    AFTER_SALE_REPLACE_GOODS_OUTER_VERIFY_OFFLINE_LOGISTICS(62, 1, "after_sale_replace_goods_outer_verify_offline_logistics_ext", "售后能力换货外部审核流转", "asrrgov", "orderId", 1),
    /**
     * 售后退货外部审核流转(无收发货单) - 63(由31衍生）
     */
    AFTER_SALE_RETURN_GOODS_PF_MANUAL_DELIVERY(63, 1, "after_sale_return_goods_pf_manual_delivery_ext", "售后退货外部平台审核无收发货单流转", "asrgmdov", "orderId", 1),
    /**
     * 结算能力 - 对账单 - 64
     */
    SETTLE_ACCOUNTS_BUSINESS_RECONCILIATION(64,1, "settle_accounts_business_reconciliation_ext", "结算对账单流转","sabr","reconciliationNo",1),
    /**
     * 商品能力 -物料新增0级外部流程 - 65
     */
    PRODUCT_SERVICE_MATERIALS_ADD_LEVEL_0(65, 1,"product_service_materials_add_level_0","物料新增0级外部流程","psmal0","materialId",1),
    /**
     * 商品能力 -物料新增1级外部流程 - 66
     */
    PRODUCT_SERVICE_MATERIALS_ADD_LEVEL_1(66, 1,"product_service_materials_add_level_1","物料新增1级外部流程","psmal1","materialId",1),
    /**
     * 商品能力 -物料新增2级外部流程 - 67
     */
    PRODUCT_SERVICE_MATERIALS_ADD_LEVEL_2(67, 1,"product_service_materials_add_level_2","物料新增2级外部流程","psmal2","materialId",1),
    /**
     * 商品能力 -物料变更/启用0级外部流程 - 68
     */
    PRODUCT_SERVICE_MATERIALS_CHANGE_OR_ENABLE_LEVEL_0(68,1,"product_service_materials_change_or_enable_level_0", "物料变更启用0级外部流程", "psmcoel0", "materialId", 1),
    /**
     * 商品能力 -物料变更/启用1级外部流程 - 69
     */
    PRODUCT_SERVICE_MATERIALS_CHANGE_OR_ENABLE_LEVEL_1(69,1,"product_service_materials_change_or_enable_level_1", "物料变更启用1级外部流程", "psmcoel1", "materialId", 1),
    /**
     * 商品能力 -物料变更/启用2级外部流程 - 70
     */
    PRODUCT_SERVICE_MATERIALS_CHANGE_OR_ENABLE_LEVEL_2(70,1,"product_service_materials_change_or_enable_level_2", "物料变更启用2级外部流程", "psmcoel2", "materialId", 1),

    /**
     * 订单能力 -送货计划外部流程 - 71
     */
    ORDER_DELIVERY_PLAN(71,1,"order_delivery_plan", "送货计划外部流程", "odp", "planId", 1),

    /**
     * 订单能力 -送货通知单外部流程 - 72
     */
    ORDER_DELIVERY_NOTICE_ORDER(72,1,"order_delivery_notice_order", "送货通知单外部流程", "odno", "orderId", 1),
    ;

    /**
     * 流程枚举值
     */
    private Integer code;
    // 0-内部流程 1-外部流程
    /**
     * 流程类型 0-内部流程，1-外部流程。定义在ProcessTypeEnum中
     */
    private Integer processType;

    /**
     * 流程的Key
     */
    private String processKey;

    /**
     * 流程名称
     */
    private String processName;

    /**
     * Camunda用户工作流必须的指派者前缀
     */
    private String assigneePrefix;

    /**
     * 流程步骤的参数字段名称
     */
    private String paramKey;

    /**
     * 启动流程后，返回的状态值
     */
    private Integer startStatus;

    ProcessEnum(Integer code, Integer processType, String processKey, String processName, String assigneePrefix, String paramKey, Integer startStatus) {
        this.code = code;
        this.processType = processType;
        this.processKey = processKey;
        this.processName = processName;
        this.assigneePrefix = assigneePrefix;
        this.paramKey = paramKey;
        this.startStatus = startStatus;
    }

    public Integer getCode() {
        return code;
    }

    public Integer getProcessType() {
        return processType;
    }

    public String getProcessKey() {
        return processKey;
    }

    public String getProcessName() {
        return processName;
    }

    public String getAssigneePrefix() {
        return assigneePrefix;
    }

    public String getParamKey() {
        return paramKey;
    }

    public Integer getStartStatus() {
        return startStatus;
    }

    /**
     * ProcessKey是否已经定义
     * @param processKey 流程的Key
     * @return 是否定义
     */
    public static boolean existProcessKey(String processKey) {
        return Arrays.stream(ProcessEnum.values()).anyMatch(processEnum -> processEnum.getProcessKey().equals(processKey));
    }

    public static ProcessEnum getInstance(Integer code) {
        return Arrays.stream(ProcessEnum.values()).filter(c -> c.getCode().equals(code)).findFirst().orElse(null);
    }

    public static boolean existProcessEnum(Integer code) {
        return Arrays.stream(ProcessEnum.values()).anyMatch(processEnum -> processEnum.getCode().equals(code));
    }

    public static boolean existCode(Integer code) {
        return Arrays.stream(ProcessEnum.values()).anyMatch(processEnum -> processEnum.getCode().equals(code));
    }

    public static String getProcessKeyByCode(Integer code) {
        ProcessEnum status = Arrays.stream(ProcessEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return status == null ? "未知" : status.getProcessKey();
    }

    public static String getAssigneePrefixByProcessKey(String processKey) {
        ProcessEnum item = Arrays.stream(ProcessEnum.values()).filter(e -> e.getProcessKey().equals(processKey)).findFirst().orElse(null);
        return item == null ? "" : item.getAssigneePrefix();
    }

    public static Integer getCodeByProcessKey(String processKey) {
        ProcessEnum item = Arrays.stream(ProcessEnum.values()).filter(e -> e.getProcessKey().equals(processKey)).findFirst().orElse(null);
        return item == null ? 0 : item.getCode();
    }

    public static String getParamKeyByProcessEnum(Integer processEnum) {
        ProcessEnum item = Arrays.stream(ProcessEnum.values()).filter(e -> e.getCode().equals(processEnum)).findFirst().orElse(null);
        return item == null ? "notFound" : item.getParamKey();
    }

    public static List<Integer> toList() {
        return Arrays.stream(ProcessEnum.values()).map(ProcessEnum::getCode).collect(Collectors.toList());
    }
}
